package com.example.cms.service.Impl;

import com.example.cms.dao.CoursesDao;
import com.example.cms.entity.Courses;
import com.example.cms.pojo.FileExport;
import com.example.cms.pojo.QueryPage;
import com.example.cms.service.CoursesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service("CoursesService")
@Transactional
public class CoursesServiceImpl implements CoursesService {

    @Autowired
    private CoursesDao coursesDao;

    @Override
    public List<Courses> getCourses(QueryPage page) {
        page.setPageSize(6);
        page.setCurr_page((page.getCurr_page()-1)*page.getPageSize());
        return coursesDao.selectCourses(page);
    }

    @Override
    public Integer getNum() {
        return coursesDao.getNum();
    }

    @Override
    public Integer removeCourses(Integer coursesId) {
        return coursesDao.deleteCourses(coursesId);
    }

    @Override
    public Integer editCourses(Courses courses) {
        return coursesDao.updateCourses(courses);
    }

    @Override
    public Integer addCourses(Courses courses) {
        return coursesDao.insertCourses(courses);
    }

    @Override
    public FileExport getCus() {
    List<Courses>courses = coursesDao.selectAll();
    FileExport fileExport =new FileExport();
        List<FileExport> fileExports =new ArrayList<FileExport>();
        String [] state ={"未激活","激活"};
        String [] sexs ={"男","女"};
        //添加表名
        fileExport.setName("课程导出数据");
        //添加表头
        List<String> titles = new ArrayList();
        titles.add("课程名称");
        titles.add("课程序号");
        titles.add("课程金额");
        titles.add("课程详述");
        titles.add("课程讲师");
        fileExport.setTitles(titles);
        //添加数据
        List<List<Object>> rows = new ArrayList();
        List<Object> c ;
        for (int i=0; i< courses.size();i++){
            c=new ArrayList<Object>();
            c.add(courses.get(i).getCourseName());
            c.add(courses.get(i).getCourseId());
            c.add(courses.get(i).getCourseMoney());
            c.add(courses.get(i).getCourseDetails());
            c.add(courses.get(i).getConsultantName());

            rows.add(c);
        }
        fileExport.setRows(rows);
        return fileExport;
    }
}
